package com.plentitude.easytrader.provider;

import android.app.SearchManager;
import android.net.Uri;
import android.provider.BaseColumns;


/**
 * Contract class for interacting with {@link WatchlistProvider}. Unless
 * otherwise noted, all time-based fields are milliseconds since epoch and can
 * be compared against {@link System#currentTimeMillis()}.
 * <p>
 * The backing {@link ContentProvider} assumes that {@link Uri} are generated
 * using stronger {@link String} identifiers, instead of {@code int}
 * {@link BaseColumns#_ID} values, which are prone to shuffle during sync.

 * @author team@getstarted.com.ua
 */
public class WatchlistContract {

    public interface DataColumns extends BaseColumns {
        String STRATEGY = "strategy";
        String TYPE = "type";
        String SETUP = "setup";
        String EPIC = "epic";
        String NAME = "name";
        String SECTOR = "sector";
        String LOW_PE_VS_SECTOR = "low_pe_vs_sector";
        String LOW_OP_MARGIN = "low_op_margin";
        String PEG = "peg";
        String EARNINGS_GROWS = "earnings_grows";
        String REVENUE_GROWTH = "revenue_growth";
        String INTEREST_COVER = "interest_cover";
        String NET_CURRENT_ASSETS = "net_current_assets";
        String NET_GEARING = "net_gearing";
        String PROJECTED_EARNINGS = "projected_earnings";
        String HIGH_PE_VS_SECTOR = "high_pe_vs_sector";
        String NEG_CURRENT_ASSETS = "neg_current_assets";
        String DECREASING_REVENUES = "decreasing_revenues";
        String HIGH_OP_MARGIN = "high_op_margin";
        String FUNDAMENTAL_SCORE = "fundamental_score";
        String MARKET = "market";
        String SECTOR_PERF = "sector_perf";
        String SECTOR_SCORE = "sector_score";
        String LONG_TRADE_SCORE = "long_trade_score";
        String SHORT_TRADE_SCORE = "short_trade_score";
        String _RSI_BUY = "_rsi_buy";
        String _MACD_BUY = "_macd_buy";
        String _STOCH_BUY = "_stoch_buy";
        String _EMA_BUY = "_ema_buy";
        String _RSI_SELL = "_rsi_sell";
        String _MACD_SELL = "_macd_sell";
        String _STOCH_SELL = "_stoch_sell";
        String _EMA_SELL = "_ema_sell";
        String BUY_INDICATOR_NUM = "buy_indicator_num";
        String SELL_INDICATOR_NUM = "sell_indicator_num";
        String BROKER_CONSENSUS = "broker_consensus";
        String LTBAT_CONSENSUS = "ltbat_consensus";
        String ADDITIONAL_INFO = "additional_info";
        String NEXT_SIG_STRENGTH = "next_sig_strength";
        String NEXT_SIG_DESC = "next_sig_desc";
        String REC_ENTRY_LEVEL = "rec_entry_level";
        String REC_STOP_LEVEL = "rec_stop_level";
        String TARGET_LEVEL = "target_level";
        String REWARD_RATIO = "reward_ratio";
        String URL_CHART = "url_chart";
        String URL_SECTOR_CHART = "url_sector_chart";
        String URL_EOD_CHART = "url3_eod_chart";
        String URL_LIVE_CHART = "url_live_chart";
        String URL_SUMMARY = "url_summary";
        String ACTIVE_SECTOR = "active_sector";
        String VOLUME_EOD = "volume_eod";
        String COMPANY_PROFILE = "company_profile";
        String ALERTS = "alerts";
        String NEWS = "news";
        String OUTLOOK = "outlook";
        String PARAMS_AND_SETTINGS = "params_and_settings";
        String DEFAULT_FIELD_VALUES = "default_field_values";
    }
    						
    public interface QuotesColumns extends BaseColumns {
        String SYMBOL = "symbol";
        String PRICE = "price";
        String DATE = "date";
        String TIME = "time";
        String CHANGE = "change";
        String OPEN = "open";
        String HIGH = "high";
        String LOW = "low";
        String VOLUME = "volume";
    }

    public static final String CONTENT_AUTHORITY = "com.plentitude.easytrader";
    private static final Uri BASE_CONTENT_URI = Uri.parse("content://" + CONTENT_AUTHORITY);
    private static final String PATH_DATA = "data";
    private static final String PATH_QUOTES = "quotes";
    private static final String PATH_SEARCH = "search";
    private static final String PATH_SEARCH_SUGGEST = "search_suggest_query";


    /**
     * Data
     */
    public static class Data implements DataColumns, BaseColumns {
        public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon().appendPath(PATH_DATA).build();
        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.easytrader.data";

        /** Default "ORDER BY" clause. */
        public static final String DEFAULT_SORT = DataColumns.EPIC + " ASC";

        /** Build {@link Uri} for requested {@link #EPIC}. */
        public static Uri buildDataUri(String epic) {
            return CONTENT_URI.buildUpon().appendPath(epic).build();
        }
    }
    
    /**
     * Quotes
     */
    public static class Quotes implements QuotesColumns, BaseColumns {
        public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon().appendPath(PATH_QUOTES).build();
        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.easytrader.quotes";

        /** Default "ORDER BY" clause. */
        public static final String DEFAULT_SORT = QuotesColumns.SYMBOL + " ASC";

        /** Build {@link Uri} for requested {@link #SYMBOL}. */
        public static Uri buildQuoteUri(String quoteSymbol) {
            return CONTENT_URI.buildUpon().appendPath(quoteSymbol).build();
        }

        public static Uri buildSearchUri(String query) {
            return CONTENT_URI.buildUpon().appendPath(PATH_SEARCH).appendPath(query).build();
        }
        
        public static String getSearchQuery(Uri uri) {
            return uri.getPathSegments().get(2);
        }

    }

    public static class SearchSuggest {
        public static final Uri CONTENT_URI =
                BASE_CONTENT_URI.buildUpon().appendPath(PATH_SEARCH_SUGGEST).build();

        public static final String DEFAULT_SORT = SearchManager.SUGGEST_COLUMN_TEXT_1
                + " COLLATE NOCASE ASC";
    }

    private WatchlistContract() {
    }
}
